<?php

namespace App\Models\Traits;

trait HasMenuType
{
    /**
     * 菜单类型：目录
     */
    const TYPE_DIRECTORY = 1;

    /**
     * 菜单类型：菜单
     */
    const TYPE_MENU = 2;

    /**
     * 菜单类型：按钮
     */
    const TYPE_BUTTON = 3;

    /**
     * 获取菜单类型列表
     *
     * @return array
     */
    public static function getMenuTypes(): array
    {
        return [
            self::TYPE_DIRECTORY => '目录',
            self::TYPE_MENU => '菜单',
            self::TYPE_BUTTON => '按钮',
        ];
    }

    /**
     * 获取菜单类型名称
     *
     * @param int $type
     * @return string
     */
    public static function getMenuTypeName(int $type): string
    {
        return self::getMenuTypes()[$type] ?? '未知';
    }

    /**
     * 检查是否为目录
     *
     * @return bool
     */
    public function isDirectory(): bool
    {
        return $this->type === self::TYPE_DIRECTORY;
    }

    /**
     * 检查是否为菜单
     *
     * @return bool
     */
    public function isMenu(): bool
    {
        return $this->type === self::TYPE_MENU;
    }

    /**
     * 检查是否为按钮
     *
     * @return bool
     */
    public function isButton(): bool
    {
        return $this->type === self::TYPE_BUTTON;
    }
}

